{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "9e0a94a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "         A1        A2        A3        A4        A5\n",
      "0  0.972540  0.971945  0.746420  0.914814  0.482034\n",
      "1  0.388428  0.719546  0.839720  0.921870  0.979861\n",
      "2  0.142005  0.474433  0.650390  0.423935  0.246703\n",
      "3  0.085524  0.184192  0.743264  0.639196  0.298486\n",
      "4  0.557508  0.691249  0.940440  0.558510  0.142068\n",
      "         A1        A2    A3        A4        A5\n",
      "0  0.972540  0.971945  0.75  0.914814  0.482034\n",
      "1  0.388428  0.719546  0.84  0.921870  0.979861\n",
      "2  0.142005  0.474433  0.65  0.423935  0.246703\n",
      "3  0.085524  0.184192  0.74  0.639196  0.298486\n",
      "4  0.557508  0.691249  0.94  0.558510  0.142068\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "df = pd.DataFrame(np.random.random([5, 5]),columns=['A1', 'A2', 'A3', 'A4', 'A5'])\n",
    "\n",
    "print(df)\n",
    "# print(df.round({'A1':1, 'A2':2,'A3':0}))\n",
    "df['A3'] = df['A3'].map(lambda x: format(x, ',.2f'))\n",
    "print(df)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "59d2bd32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  A1        A2    A3        A4        A5\n",
      "0  0  0.849995  0.40  0.927317  0.080658\n",
      "1  1  0.160257  0.20  0.970617  0.297097\n",
      "2  1  0.701489  0.94  0.675388  0.895179\n",
      "3  1  0.045252  0.70  0.039509  0.271325\n",
      "4  0  0.812200  0.29  0.772883  0.036685\n"
     ]
    }
   ],
   "source": [
    "df['A1'] = df['A1'].map(lambda x: format(x, '.0f'))\n",
    "print(df)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "acf05bcd",
   "metadata": {},
   "outputs": [],
   "source": [
    "df['A1'] = df['A1'].map(lambda x: format(x, ','))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "6a269a29",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   A1        A2        A3        A4        A5\n",
      "0  0.8489351804715608  0.348178  0.695754  0.465985  0.164122\n",
      "1  0.4467468121126381  0.766651  0.653182  0.855221  0.611582\n",
      "2  0.5334647107889692  0.893140  0.792979  0.228520  0.514244\n",
      "3  0.7356590556561104  0.697084  0.670955  0.152981  0.562172\n",
      "4  0.6275642320563858  0.998132  0.210578  0.659018  0.720986\n"
     ]
    }
   ],
   "source": [
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "de881de1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                    A1    A2    A3    A4    A5\n",
      "0   0.5094264847909694  0.15  0.37  0.27  0.93\n",
      "1   0.9674680321078782  0.10  0.01  0.19  0.57\n",
      "2   0.7125556308886598  0.41  0.56  0.99  0.80\n",
      "3  0.08544550107914994  0.35  0.34  0.61  0.67\n",
      "4   0.5934735997215727  0.78  0.04  0.47  0.64\n"
     ]
    }
   ],
   "source": [
    "print(df.round(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "320ccf88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A1</th>\n",
       "      <th>A2</th>\n",
       "      <th>A3</th>\n",
       "      <th>A4</th>\n",
       "      <th>A5</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.8489351804715608</td>\n",
       "      <td>0.35</td>\n",
       "      <td>0.695754</td>\n",
       "      <td>0.465985</td>\n",
       "      <td>0.164122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.4467468121126381</td>\n",
       "      <td>0.77</td>\n",
       "      <td>0.653182</td>\n",
       "      <td>0.855221</td>\n",
       "      <td>0.611582</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.5334647107889692</td>\n",
       "      <td>0.89</td>\n",
       "      <td>0.792979</td>\n",
       "      <td>0.228520</td>\n",
       "      <td>0.514244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.7356590556561104</td>\n",
       "      <td>0.70</td>\n",
       "      <td>0.670955</td>\n",
       "      <td>0.152981</td>\n",
       "      <td>0.562172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.6275642320563858</td>\n",
       "      <td>1.00</td>\n",
       "      <td>0.210578</td>\n",
       "      <td>0.659018</td>\n",
       "      <td>0.720986</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   A1    A2        A3        A4        A5\n",
       "0  0.8489351804715608  0.35  0.695754  0.465985  0.164122\n",
       "1  0.4467468121126381  0.77  0.653182  0.855221  0.611582\n",
       "2  0.5334647107889692  0.89  0.792979  0.228520  0.514244\n",
       "3  0.7356590556561104  0.70  0.670955  0.152981  0.562172\n",
       "4  0.6275642320563858  1.00  0.210578  0.659018  0.720986"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.round({'A1':1, 'A2':2})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73a23119",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
